package io.github.harmonly.skyblock.util;

public class TimeHelper {

    // SkyBlock 起始时间的毫秒数
    public static final long SKYBLOCK_START_MILLIS = 1560275700000L;

    // 时间常量定义
    private static final int DAYS_IN_MONTH = 31;
    private static final int MONTHS_IN_YEAR = 12;
    private static final int DAYS_IN_YEAR = MONTHS_IN_YEAR * DAYS_IN_MONTH;

    // 现实世界时间单位的毫秒数
    public static final long MILLIS_PER_REAL_MINUTE = 60 * 1000;
    public static final long MILLIS_PER_REAL_HOUR = MILLIS_PER_REAL_MINUTE * 60;
    public static final long MILLIS_PER_REAL_DAY = 24 * MILLIS_PER_REAL_HOUR;

    // Minecraft 时间单位的毫秒数
    private static final long MILLIS_PER_MC_MINUTE = 833;
    private static final long MILLIS_PER_MC_HOUR = 50 * 1000;
    private static final long MILLIS_PER_MC_DAY = 20 * MILLIS_PER_REAL_MINUTE;
    private static final long MILLIS_PER_MC_MONTH = DAYS_IN_MONTH * MILLIS_PER_MC_DAY;
    private static final long MILLIS_PER_MC_YEAR = DAYS_IN_YEAR * MILLIS_PER_MC_DAY;

    // 私有构造方法，防止实例化
    private TimeHelper() {
    }

    /**
     * 获取当前时间的毫秒数（相对于开始时间）
     */
    public static long getCurrentTimeMillis() {
        return System.currentTimeMillis() - SKYBLOCK_START_MILLIS;
    }

    /**
     * 获取当前时间的年份
     */
    public static int getYear() {
        long currentTimeMillis = getCurrentTimeMillis();
        return (int) (currentTimeMillis / MILLIS_PER_MC_YEAR) + 1;
    }

    /**
     * 获取当前时间的月份
     */
    public static int getMonth() {
        long currentTimeMillis = getCurrentTimeMillis();
        return (int) ((currentTimeMillis % MILLIS_PER_MC_YEAR) / MILLIS_PER_MC_MONTH) + 1;
    }

    /**
     * 获取当前时间的日期（天）
     */
    public static int getDay() {
        long currentTimeMillis = getCurrentTimeMillis();
        return (int) ((currentTimeMillis % MILLIS_PER_MC_MONTH) / MILLIS_PER_MC_DAY) + 1;
    }

    /**
     * 获取当前时间的小时
     */
    public static int getHour() {
        long currentTimeMillis = getCurrentTimeMillis();
        return (int) ((currentTimeMillis % MILLIS_PER_MC_DAY) / MILLIS_PER_MC_HOUR);
    }

    /**
     * 获取当前时间的分钟
     */
    public static int getMinutes() {
        long currentTimeMillis = getCurrentTimeMillis();
        return (int) ((currentTimeMillis % MILLIS_PER_MC_HOUR) / MILLIS_PER_MC_MINUTE);
    }
}
